import * as fs from 'fs';
import * as path from 'path';
const isProd = process.env.NODE_ENV == 'prod';

function parseEnv() {
  const localEnv = path.resolve('src/.env');
  const prodEnv = path.resolve('src/.env.prod');
  console.log('parseEnv1', localEnv, fs.existsSync(localEnv));
  console.log('parseEnv2', prodEnv, fs.existsSync(prodEnv));
  if (!fs.existsSync(localEnv) && !fs.existsSync(prodEnv)) {
    throw new Error('缺少环境配置文件');
  }

  const filePath = isProd && fs.existsSync(prodEnv) ? prodEnv : localEnv;
  return { path: filePath };
}
export default parseEnv();
